package com.loto.webapp.action.ajax;

import org.apache.struts2.json.annotations.JSON;

import com.loto.webapp.bo.UserBo;
import com.loto.webapp.common.BaseAction;
import com.loto.webapp.util.Constants;

public class LoginAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8468350083140892620L;

	private UserBo userBo;

	private String username;

	private String password;

	private String identitycode;

	private String msg;

	@SuppressWarnings("unchecked")
	public String execute() throws Exception {
		if (username == null || username.length() <= 0 || password == null
				|| password.length() <= 0)
			this.msg = "0";
		else if (!getSession("ValidateCode").toString().equals(identitycode))
			this.msg = "-2";
		else if (this.userBo.login(username, password)) {
			setSession(Constants.USERNAME_KEY, username);
			this.msg = "SUC";
		} else {
			this.msg = "-1";
		}
		return SUCCESS;
	}

	@JSON(serialize = false)
	public UserBo getUserBo() {
		return userBo;
	}

	public void setUserBo(UserBo userBo) {
		this.userBo = userBo;
	}

	@JSON(serialize = false)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@JSON(serialize = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@JSON(serialize = false)
	public String getIdentitycode() {
		return identitycode;
	}

	public void setIdentitycode(String identitycode) {
		this.identitycode = identitycode;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
